package com.kaishengit.action;

import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.kaishengit.pojo.TaskType;
import com.kaishengit.pojo.User;
import com.kaishengit.service.TaskTypeService;
import com.kaishengit.service.UserService;
import com.opensymphony.xwork2.ActionSupport;


public class AppAction extends ActionSupport implements SessionAware,ServletRequestAware {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String code;
	private UserService userService;
	private User user;
	private Map<String,Object> session;
	private TaskTypeService taskTypeService;
	private HttpServletRequest request;
	
	public String execute(){
		return SUCCESS;
	}
	public String exit(){
		HttpSession session = request.getSession();
		session.invalidate();
		return SUCCESS;
	}
	public String login(){
		user = userService.findByUsername(user);
		if(user == null){
			code = "10001";
			return ERROR;
			
		}else{
			session.put("curr_user", user);
			List<TaskType> list = taskTypeService.findTypeByUser(user);
			session.put("taskTypeList",list);
			return SUCCESS;
		}
		
	}
	
	
	
	
	//set get

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
		
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}
	public void setTaskTypeService(TaskTypeService taskTypeService) {
		this.taskTypeService = taskTypeService;
	}
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		
	}
	
	
}
